import Vue from 'vue';
import Router from 'vue-router';

const Home = () => import('views/home/Home.vue');
const Category = () => import('views/category/Category.vue');
const Cart = () => import('views/cart/Cart.vue');
const Profile = () => import('views/profile/Profile.vue');
const Detail = () => import('views/detail/Detail.vue');

Vue.use(Router);

const routes = [
  {
    path: '',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {
      title: '商城首页'
    }
  },
  {
    path: '/category',
    name: 'Category',
    component: Category,
    meta: {
      title: '商品分类'
    }
  },
  {
    path: '/cart',
    name: 'Cart',
    component: Cart,
    meta: {
      title: '我的购物车'
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: Profile,
    meta: {
      title: '个人信息'
    }
  },
  {
    // path: '/detail/:iid', // params
    path: '/detail', // query
    name: 'Detail',
    component: Detail,
    meta: {
      title: '商品详情页'
    }
  }
];

const router = new Router({
  routes,
  mode: 'history'
});

export default router;

router.beforeEach((to, from, next) => {
  document.title = to.matched[0].meta.title;
  next();
});
